package com.woniuxy.factory.controller;

import com.woniuxy.factory.entity.RepairApply;
import com.woniuxy.factory.entity.ResponseResult;
import com.woniuxy.factory.service.ApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/application")
public class ApplyController {
    @Autowired
    ApplyService applyService;

    @ResponseBody
        @RequestMapping("/equipment")
    public ResponseResult equipmentApply(Integer eid, String reason) {
        //参数验证
        ResponseResult<Object> res = new ResponseResult<>();
        if (eid == null || reason == null || reason.isEmpty()) {
            res.setCode(1);
            res.setMsg("参数不合法");
            return res;
        }
        //执行业务逻辑
        try {
            applyService.repairApply(eid, reason);
        } catch (Exception e) {
            res.setCode(1);
            res.setMsg(e.getMessage());
            return res;
        }
        res.setCode(0);
        res.setMsg("申请已提交，等待维修人员维修");
        return res;
    }

    @ResponseBody
    @RequestMapping("/equipment/show")
    public ResponseResult showEquipmentApply(RepairApply repairApply,String searchTime) {
        //System.out.println(repairApply);
        ResponseResult<Object> res = new ResponseResult<>();
        List<RepairApply> repairApplies = applyService.showEquipmentApply(repairApply,searchTime);
        //数据封装
        res.setCode(0);
        res.setMsg("查询成功");
        res.setData(repairApplies);
        return res;
    }
    @ResponseBody
    @RequestMapping("/equipment/repair")
    public ResponseResult searchRepairApply(RepairApply repairApply){
        ResponseResult<Object> res = new ResponseResult<>();
        return res;
    }
}
